package robot;

import java.util.logging.Logger;

import com.google.wave.api.Blip;
import com.google.wave.api.ElementType;
import com.google.wave.api.Event;
import com.google.wave.api.FormElement;
import com.google.wave.api.FormView;
import com.google.wave.api.TextView;

public class StatusFormController extends BaseFormController
{
	/**
	 * The element id of the name label.
	 */
	private static final String NAME_LABEL_ID = "name_label";

	/**
	 * The caption of the name label.
	 */
	private static final String NAME_LABEL_CAPTION = "Name:";

	/**
	 * The element id of the name input box.
	 */
	private static final String NAME_INPUT_ID = "name_input";

	/**
	 * The element id of the name label.
	 */
	private static final String STATUS_LABEL_ID = "status_label";

	/**
	 * The caption of the name label.
	 */
	private static final String STATUS_LABEL_CAPTION = "Current Status:";

	/**
	 * The element id of the name input box.
	 */
	private static final String STATUS_INPUT_ID = "status_input";

	/**
	 * The caption of the login button.
	 */
	private static final String SUBMIT_BUTTON_CAPTION = "Submit";

	private static final Logger log = Logger.getLogger(StatusFormController.class.getName());


	public StatusFormController(Blip blip)
	{
		super(blip);
	}

	/**
	 * Renders status form
	 */
	public void renderForm()
	{
		TextView document = blip.getDocument();

		// content of the root blip gets duplicated unless previous text is
		// deleted
		document.delete();
		document.append("\n\n");

		// Append the name input box.
		document.appendElement(new FormElement(ElementType.LABEL,
				NAME_LABEL_ID, NAME_LABEL_CAPTION));
		document.appendElement(new FormElement(ElementType.INPUT,
				NAME_INPUT_ID, ""));

		// Append the status input box.
		document.appendElement(new FormElement(ElementType.LABEL,
				STATUS_LABEL_ID, STATUS_LABEL_CAPTION));
		document.appendElement(new FormElement(ElementType.INPUT,
				STATUS_INPUT_ID, ""));

		// Append the submit button.
		document.append("\n");
		document.appendElement(new FormElement(ElementType.BUTTON,
				SUBMIT_BUTTON_ID, SUBMIT_BUTTON_CAPTION));

	}

	/**
	 * Checks whether the submit button is clicked or not.
	 * 
	 * @return A {@code true} if the login button is clicked.
	 */
	public boolean isSubmitButtonClicked(Event event)
	{
		return SUBMIT_BUTTON_ID.equals(event.getButtonName());
	}
	
	/**
	 * Get the name
	 * 
	 * @return value of name input field
	 */
	public String getNameInput()
	{
		FormView formView = blip.getDocument().getFormView();
		return formView.getFormElement(NAME_INPUT_ID).getValue().trim();
	}
	
	/**
	 * Get the status
	 * 
	 * @return value of status input field
	 */
	public String getStatusInput()
	{
		FormView formView = blip.getDocument().getFormView();
		return formView.getFormElement(STATUS_INPUT_ID).getValue().trim();
	}


}
